#include <iostream>
#include <string>
#include <ctime>
#include <unistd.h>
#include <pthread.h>

using namespace std;

void *threadRun(void *arg)
{
    const char *ps = static_cast<const char*>(arg);

    while(true)
    {
        cout << "线程 " << ps << " 正在运行" << endl;
        sleep(1);
    }

    pthread_exit((void*)10);
}

int main()
{
    pthread_t t;
    pthread_create(&t, nullptr, threadRun, (void*)"Hello Thread");

    // 3秒后关闭线程
    sleep(3);

    pthread_cancel(t);

    void *retval = nullptr;
    pthread_join(t, &retval);

    // 细节：使用 int64_t 而非 uint64_t
    cout << "线程 " << t << " 已退出，退出信息为 " << (int64_t)retval << endl;
    return 0;
}
